package com.zq.product.controller;


import com.github.pagehelper.PageInfo;
import com.zq.common.util.Result;
import com.zq.product.dao.entity.Brand;
import com.zq.product.service.IBrandService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author 张乔
 * @since 2025-05-26
 */
@RestController
@RequestMapping("/product/brand")
@Slf4j
public class BrandController {

    @Resource
    private IBrandService brandService;

//    根据条件分页查询品牌
    @GetMapping("getAll/{page}/{limit}")
    public Result<PageInfo<Brand>> findByPage(@PathVariable Integer page,
                                              @PathVariable Integer limit,
                                              @RequestParam(value = "brandName",required = false) String brandName) {
        PageInfo<Brand> pageInfo = brandService.findByPage(page, limit, brandName);
        return Result.successData(pageInfo);
    }
    //    查询所有品牌
    @GetMapping("/findAll")
    public Result<List<Brand>> findAll() {
        List<Brand> list = brandService.list();
        return Result.successData(list);
    }




//    保存品牌
    @PostMapping("save")
    public Result<String> save(@RequestBody Brand brand) {
        brandService.saveBrand(brand);
    return Result.successMessage("保存成功");
    }


//    根据id修改品牌
    @PutMapping("updateById")
    public Result<String> updateById(@RequestBody Brand brand) {
        log.info("修改品牌信息：{}",brand);
        brandService.updateByIdApi(brand);
        return Result.success();
    }

    //    根据id删除品牌
    @DeleteMapping("/deleteById/{id}")
    public Result<String> deleteById(@PathVariable Long id) {
        brandService.deleteById(id);
        return Result.success();
    }



}
